package com.ziq.zcamp.activities

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.graphics.*
import android.os.Bundle
import android.view.Display
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ScreenUtils
import com.facebook.imagepipeline.request.ImageRequest
import com.gmlive.camp.dialog.share.ShareDialog
import com.google.android.material.appbar.AppBarLayout
import com.ziq.base.base.BaseActivity
import com.ziq.base.extension.*
import com.ziq.base.utils.SystemBarUtil
import com.ziq.zcamp.R
import com.ziq.zcamp.bean.activities.ActivitiesContentInfo
import com.ziq.zcamp.bean.activities.ActivitiesInfo
import com.ziq.zcamp.databinding.*
import com.ziq.zcamp.dialog.ActivitiesPriceTypeDialog
import com.ziq.zcamp.dialog.ActivitiesProductPropertyDialog
import com.ziq.zcamp.dialog.share.ActionItem
import com.ziq.zcamp.manager.GlobalContextManager
import com.ziq.zcamp.mine.PersonalHomePageActivity
import com.ziq.zcamp.mine.PicturePreviewActivity
import com.ziq.zcamp.place.PlaceDetailActivity
import com.ziq.zcamp.post.MapActivity
import com.ziq.zcamp.util.ImageUtil
import com.ziq.zcamp.util.blurry.Blurry
import com.ziq.zcamp.view.StatusView
import com.ziq.zcamp.view.longimage.LongImage
import com.ziq.zcamp.view.longimage.LongImageInfo
import dagger.hilt.android.AndroidEntryPoint
import java.io.Serializable
import java.lang.ref.SoftReference

@AndroidEntryPoint
class ActivitiesDetailsActivity : BaseActivity() {

    companion object {

        const val SOURCE_LIST = 0
        const val SOURCE_LINK = 1
        const val SOURCE_QR_CODE = 2
        const val SOURCE_PERSONAL = 3
        const val SOURCE_ORDER = 4
        const val SOURCE_OPEN = 5
        const val SOURCE_BANNER = 6
        const val SOURCE_PLACE_DETAIL = 11	//营地详情页

        private const val ITEM_HEAD = 0
        private const val ITEM_TEXT = 2
        private const val ITEM_IMAGE = 1
        private const val ITEM_FLOW = 3
        private const val ITEM_TAIL = 4
        private const val ITEM_LONG_IMAGE = 99

        const val ACTIVITIES_ID = "ACTIVITIES_ID"
        const val ACTIVITIES = "ACTIVITIES"
        const val ACTIVITIES_SOURCE = "ACTIVITIES_SOURCE"
        fun open(context: Context, activitiesId : Long, info : ActivitiesInfo?= null, from : Int ?= SOURCE_LIST ){
            if (info!=null && activitiesId != info.id){
                return
            }
            val intent = Intent(context, ActivitiesDetailsActivity::class.java)
            intent.putExtra(ACTIVITIES_ID,activitiesId)
            if (info!=null){
                intent.putExtra(ACTIVITIES,info as Serializable)
            }
            intent.putExtra(ACTIVITIES_SOURCE,from)
            GlobalContextManager.startActivity(context, intent)
        }
    }

    private val binding: ActivityActivitiesDetailsBinding by binding()
    private val mViewModel: ActivitiesDetailsViewModel by viewModels()
    private val mAdapter by lazy { Adapter(ScreenUtils.getScreenWidth()) }

    //票种信息弹窗
    private val ticketDialog by lazy { ActivitiesPriceTypeDialog(this,mViewModel) }
    //库存信息
    private val stockDialog by lazy { ActivitiesProductPropertyDialog(this,mViewModel) }

    private val finishRunnable : Runnable by lazy {
        Runnable{
            finish()
        }
    }

    private var source :Int ?= null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        try {
            val id : Long = if(intent.hasExtra(ACTIVITIES_ID)){
                intent.getLongExtra(ACTIVITIES_ID,0L)
            }else{
                0
            }
            val info : ActivitiesInfo ? = if (intent.hasExtra(ACTIVITIES)){
                intent.getSerializableExtra(ACTIVITIES) as ActivitiesInfo
            }else{
                null
            }
            source = if (intent.hasExtra(ACTIVITIES_SOURCE)){
                intent.getIntExtra(ACTIVITIES_SOURCE, SOURCE_LIST)
            }else{
                null
            }
            mViewModel.init(id,info)
        }catch (e:Exception){
            println("$e")
        }

        SystemBarUtil.immerseStatusBar(this.window, statusBarIsLight = true)

        binding.root

        val targetHeight = GlobalContextManager.getResources().getDimensionPixelSize(R.dimen.dimens_dip_40)
        binding.appBarLayout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
            val remain = appBarLayout.totalScrollRange - (-verticalOffset)
            if(remain <= targetHeight){
                binding.toolbar.visibility = View.VISIBLE
                binding.clActivitiesDetails.visibility = View.INVISIBLE
            }else {
                binding.toolbar.visibility = View.GONE
                binding.clActivitiesDetails.visibility = View.VISIBLE
            }
        })
        binding.detail.adapter = mAdapter
        binding.detail.layoutManager = LinearLayoutManager(this)
        binding.detail.addItemDecoration(object : RecyclerView.ItemDecoration(){
            val paint :Paint = Paint()
            override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
                super.onDrawOver(c, parent, state)
                val childCount = parent.childCount
                for (i in 0 until childCount) {
                    if (i == 0)  {
                        val top = parent.paddingTop
                        paint.color = resources.getColor(R.color.white)
                        c.drawRect(12F.dp,top.toFloat(),parent.width- 12F.dp,top + 20F.dp,paint)
                        paint.color = resources.getColor(R.color.color_d9d9d9)
                        val rect = RectF(parent.width/2 - 20F.dp,top+8F.dp,parent.width/2 + 20F.dp,top + 12F.dp)
                        c.drawRoundRect(rect,2F.dp,2F.dp,paint)
                    }
                }

            }
        })

        clickEvent()

        mViewModel.poster.observe(this){
            //避免闪一下影响过渡，用和外面一样的尺寸
            ImageUtil.updateImageFromNetwork(binding.ivPoster,it.url, it?.width?:0,it?.height?:0)
            setBackground(it.url?:"")
        }
        mViewModel.name.observe(this){
            binding.tvActivitiesName.text = it
            binding.tvBarName.text = it
        }
        mViewModel.time.observe(this){
            binding.tvActivitiesTime.text = it
        }
        mViewModel.price.observe(this){
            binding.tvActivitiesPrice.text = it
        }
        mViewModel.location.observe(this){
            binding.tvActivitiesPlace.text = it
        }
        mViewModel.camp.observe(this){
            if (it!=null && !it.isInfoEmpty()){
                binding.groupCamp.visibility = View.VISIBLE
                binding.tvActivitiesCamp.text = it.name
            }else{
                binding.groupCamp.visibility = View.GONE
            }
        }
        mViewModel.organizer.observe(this){
            if (it!=null){
                binding.linearLayout.visibility = View.VISIBLE
                ImageUtil.updateImageFromNetwork(binding.ivActivitiesHeadPortrait,it.portrait, ImageRequest.CacheChoice.DEFAULT)
                binding.tvActivitiesUserName.text = it.nick
            }else{
                binding.linearLayout.visibility = View.GONE
            }
        }
        mViewModel.content.observe(this){
            if (!it.isNullOrEmpty()){
                mAdapter.setDataList(it)
            }
        }
        mViewModel.showLaunchActivities.observe(this){
            if (it == true){
                binding.groupInitiateActivities.visibility = View.VISIBLE
            }else{
                binding.groupInitiateActivities.visibility = View.GONE
            }
            if (binding.groupInitiateActivities.visibility == View.GONE && binding.btJoinActivities.visibility == View.GONE){
                binding.clBottomButtonGroup.visibility = View.GONE
            }
        }
        //0收费——在觅野售票；1免费；2收费，不在觅野售票
        //控制是否显示
        mViewModel.freeType.observe(this){
            if (it == null)return@observe
            when(it){
                0->{
                    binding.clBottomButtonGroup.visibility = View.VISIBLE
                    binding.btJoinActivities.visibility = View.VISIBLE
                }
                1->{
                    binding.clBottomButtonGroup.visibility = View.VISIBLE
                    binding.btJoinActivities.visibility = View.GONE
                }
                //收费，不在觅野售票 不显示底部栏
                2->{
                    binding.clBottomButtonGroup.visibility = View.GONE
                    binding.btJoinActivities.visibility = View.VISIBLE
                }
                else->{}
            }
            if (binding.groupInitiateActivities.visibility == View.GONE && binding.btJoinActivities.visibility == View.GONE){
                binding.clBottomButtonGroup.visibility = View.GONE
            }
        }

        //控制内容以及是否可以点击
        mViewModel.actStatus.observe(this){
            if (it == null)return@observe
            when(it){
                1->{
                    binding.btJoinActivities.isEnabled = true
                    binding.btJoinActivities.text = getString(R.string.activities_join_now)
                    binding.ivFinishMask.visibility = View.GONE
                }
                2->{
                    binding.btJoinActivities.isEnabled = false
                    binding.btJoinActivities.text = getString(R.string.activities_sold_out)
                    binding.ivFinishMask.visibility = View.GONE
                }
                3->{
                    binding.btJoinActivities.isEnabled = false
                    binding.btJoinActivities.text = getString(R.string.activities_time_over)
                    binding.ivFinishMask.visibility = View.VISIBLE
                }
                else->{}
            }
        }

        mViewModel.ticketData.observe(this){
            if (showDialog){
                ticketDialog.setTicketData(it)
                showDialog = false
            }
        }
        mViewModel.inventoryData.observe(this){
            stockDialog.initData(it)
            stockDialog.show()
        }

        mViewModel.isOffLine.observe(this){
            if (it){
                binding.cdlRoot.visibility = View.INVISIBLE
                binding.cdlRoot.post{
                    binding.cdlRoot.visibility = View.GONE
                }
                binding.clBottomButtonGroup.visibility = View.GONE
                binding.clOffline.visibility = View.VISIBLE
                binding.llRoot.post {
                    binding.llRoot.setBackgroundColor(resources.getColor(R.color.white))
                }
                binding.llRoot.setBackgroundColor(Color.parseColor("#FFFFFF"))

                GlobalContextManager.mainHandler.postDelayed(finishRunnable,500)
            }
        }

        mViewModel.ticketError.observe(this){
            if (it && ticketDialog.isShowing){
                ticketDialog.showStatusError()
            }
        }

        mViewModel.statusShow.observe(this) {
            when (it) {
                StatusView.IDLE -> {
                    binding.statusView.setStatus(StatusView.IDLE)
                }
                StatusView.LOADING -> {
                    binding.statusView.setStatus(StatusView.LOADING)
                }
                StatusView.NO_DATA -> {
                    binding.statusView.setStatus(
                        StatusView.NO_DATA,
                        isCenter = false,
                        marginTop = 86.dp,
                        imgSrc = R.drawable.pic_no_content_camp,
                        imgWidth = 235.dp,
                        imgHeight = 151.dp,
                        msg = "暂时没有内容~"
                    )
                }
                StatusView.NET_ERROR -> {
                    binding.statusView.setStatus(
                        StatusView.NET_ERROR,
                        isCenter = false,
                        marginTop = 86.dp,
                        updateActionBtn = { btn ->
                            btn.click {
                                mViewModel.requestData()
                            }
                        })
                }
            }
        }

        mViewModel.vrInfo.observe(this){
            if (it == null)return@observe
            if (it.exist_vr == true){
                binding.llActivitiesVr.visibility = View.VISIBLE
            }else{
                binding.llActivitiesVr.visibility = View.GONE
            }
        }

    }

    override fun onResume() {
        super.onResume()
        mViewModel.requestData()
    }

    private fun setBackground(url :String){
        val windowManager: WindowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display: Display = windowManager.defaultDisplay
        val outPoint = Point()
        display.getRealSize(outPoint)
        outPoint.x
        ImageUtil.getBitmap(0, url, outPoint.x, outPoint.y, ImageUtil.imageMaxSize,BitmapLoadListener(this))
    }

    private class BitmapLoadListener(activity : ActivitiesDetailsActivity) : ImageUtil.BitmapLoadListener{
        val softReference : SoftReference<ActivitiesDetailsActivity> by lazy {
            SoftReference(activity)
        }
        override fun onBitmapLoaded(id: Int, bitmap: Bitmap?) {
            softReference.get()?.let {
                if (ImageUtil.isBitmapAvailable(bitmap) && it.mViewModel.isOffLine.value != true) {
                    Blurry.with(it)
                        .radius(10)
                        .sampling(8)
                        .color(it.resources.getColor(R.color.black_translucent_60))
                        .from(bitmap)
                        .into(it.binding.llRoot)
                }
            }
        }

    }

    private var showDialog = false
    @SuppressLint("ClickableViewAccessibility")
    private fun clickEvent(){
        binding.ivBack.click { finish() }
        binding.ivBarBack.click { finish() }
        binding.back.click { finish() }
        binding.ivInitiateActivities.click {
//            ActivitiesUploadActivity.open(this)
        }
        binding.btJoinActivities.click {
            showDialog = true
            ticketDialog.show()
        }
        binding.tvActivitiesCamp.click {
            PlaceDetailActivity.open(this,mViewModel.camp.value?.id,mViewModel.camp.value?.name?:"","active_detail")
        }
        binding.ivPoster.click {
            val list = ArrayList<String>()
            list.add(mViewModel.poster.value?.url?:"")
            PicturePreviewActivity.open(this, list, 0)
        }
        binding.linearLayout.click {
            PersonalHomePageActivity.open(this,mViewModel.organizer.value?.id?:0)
        }

        binding.tvActivitiesPlace.click {
            val item = mViewModel.info
            item?.let {
                if(item.longitude?.isNotEmpty() == true && item.latitude?.isNotEmpty() == true){
                    MapActivity.showMapNavigationList(this@ActivitiesDetailsActivity, item.location_addr?:"",
                        item.latitude?:"", item.longitude?:"", "active_detail")
                } else {
                    val errMsg = GlobalContextManager.getString(R.string.data_error)
                    Toast.makeText(GlobalContextManager.appContext, errMsg, Toast.LENGTH_SHORT).show()
                }

            }
        }

        binding.ivShare.click {
            if(mViewModel.info == null){
                return@click
            }
            val tools = mutableListOf<ActionItem>()
            ShareDialog(this, tools,ShareDialog.ACTIVE_DETAIL, desc = mViewModel.id.toString())
                .setActivityData(mViewModel.info!!)
                .show()
        }

        binding.ivBarShare.click {
            if(mViewModel.info == null){
                return@click
            }
            val tools = mutableListOf<ActionItem>()
            ShareDialog(this, tools,ShareDialog.ACTIVE_DETAIL, desc = mViewModel.id.toString())
                .setActivityData(mViewModel.info!!)
                .show()
        }
        binding.llActivitiesVr.click {
            if (mViewModel.vrInfo.value == null)
                return@click
//            WebActivity.openWebView(this, mViewModel.vrInfo.value?.url?:"", mViewModel.name.value?:"")
        }

    }

    fun showPhoneNumberDialog(){
//        PhoneCallBottomSheetDialog.Builder(this)
//            .setList(listOf(mViewModel.getActiveContactNumber()), object : PhoneCallBottomSheetDialog.ActionCallBack {
//                @SuppressLint("MissingPermission")
//                override fun onActionClick(dialog: PhoneCallBottomSheetDialog, position: Int, text: String) {
//                    dialog.dismiss()
//                    PermissionUtil.requestPhoneCallPermission(this@ActivitiesDetailsActivity, RxPermissions(this@ActivitiesDetailsActivity), onGrant = {
//                        this@ActivitiesDetailsActivity.startActivity(IntentUtils.getCallIntent(text))
//                    })
//                }
//            })
//            .build()
//            .show()
    }

    override fun finish() {
        super.finish()
    }

    private inner class Adapter(screenWidth: Int) : RecyclerView.Adapter<BindingViewHolder<*>>(){
        var contentImageWidth = 0
        init {
            contentImageWidth = screenWidth - GlobalContextManager.getResources().getDimensionPixelSize(R.dimen.dimens_dip_32)
        }

        private val usableWidth by lazy {
            (ScreenUtils.getScreenWidth() - GlobalContextManager.getResources().getDimensionPixelSize(
                R.dimen.dimens_dip_32))
        }

        private val screenHeight by lazy {
            ScreenUtils.getScreenHeight()
        }

        private val bitmapOption by lazy {
            BitmapFactory.Options().apply {
                inPreferredConfig = Bitmap.Config.RGB_565
            }
        }

        private val urlMap = mutableMapOf<String,String>()
        private val imageDecoder = mutableMapOf<String, BitmapRegionDecoder?>()

        private var dataList : MutableList<LongImageInfo<ActivitiesContentInfo>> = mutableListOf()

        @SuppressLint("NotifyDataSetChanged")
        fun setDataList(list : MutableList<ActivitiesContentInfo>){
            dataList.clear()
            val head = ActivitiesContentInfo()
            head.type = ITEM_HEAD
            dataList.add(LongImageInfo(false, LongImage("",0,0,0),head))

//            dataList.addAll(list)
            for (info in list){
                if (info.type == 1 && (info.image?.height?:0)>ImageUtil.imageMaxSize){
                    val divisionNum = ((info.image?.height?:0)/screenHeight.toFloat()).toInt() + 1
                    for (i in 0 until divisionNum){
                        val bottom = if (((i+1)*screenHeight)>(info.image?.height?:0)){
                            (info.image?.height?:0)
                        }else{
                            ((i+1)*screenHeight)
                        }
                        val top = if (i*screenHeight > (info.image?.height?:0)){
                            (info.image?.height?:0)
                        }else{
                            i*screenHeight
                        }
                        launchWithTryAsyncGlobal(whenTry = {
                            if (!info.image?.url.isNullOrEmpty() && !ImageUtil.isImageDownloaded(info.image?.url)){
                                ImageUtil.getBitmap(0,info.image?.url,info.image?.width?:0,info.image?.height?:0
                                ) { _, _ ->
                                    notifyDataSetChanged()
                                }
                            }
                        })
                        val index = when (i){
                            0 -> 0
                            divisionNum -1 -> 2
                            else -> 1
                        }
                        dataList.add(LongImageInfo(true,LongImage(info.image?.url?:"",(info.image?.width?:0),top,bottom,index),info))

                    }
                }else {
                    dataList.add(LongImageInfo(false,LongImage("",0,0,0),info))
                }
            }

            val tail = ActivitiesContentInfo()
            tail.type = ITEM_TAIL
            dataList.add(LongImageInfo(false, LongImage("",0,0,0),tail))
            notifyDataSetChanged()
        }

        override fun getItemId(position: Int): Long {
            return position.toLong()
        }

        override fun getItemViewType(position: Int): Int {
            if (dataList[position].hasLong){
                return ITEM_LONG_IMAGE
            }
            return dataList[position].other.type?:1
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindingViewHolder<*> {
            when(viewType){
                ITEM_HEAD -> {
                    return createBindingViewHolder<ItemActivitiesHeadBinding>(parent)
                }
                ITEM_TEXT -> {
                    return createBindingViewHolder<ItemArticleContentBinding>(parent)
                }
                ITEM_IMAGE -> {
                    return createBindingViewHolder<ItemArticleContentBinding>(parent)
                }
                ITEM_FLOW -> {
                    return createBindingViewHolder<ItemActivitiesFlowBinding>(parent)
                }
                ITEM_TAIL -> {
                    return createBindingViewHolder<ItemActivitiesTailBinding>(parent)
                }
                ITEM_LONG_IMAGE -> {
                    return createBindingViewHolder<ItemLongImageBinding>(parent)
                }
                else -> {
                    return createBindingViewHolder<ItemArticleContentBinding>(parent)
                }
            }
        }

        override fun onBindViewHolder(holder: BindingViewHolder<*>, position: Int) {
            when(holder.binding){
                is ItemActivitiesHeadBinding ->{
                    onBindHeadViewHolder()
                }
                is ItemArticleContentBinding ->{
                    onBindContentViewHolder(holder.itemView,position)
                }
                is ItemActivitiesFlowBinding ->{
                    onBindFlowViewHolder(holder.itemView,position)
                }
                is ItemActivitiesTailBinding ->{
                    onBindTailViewHolder(holder.itemView)
                }
                is ItemLongImageBinding ->{
                    onBindLongImage(holder.itemView,position)
                }
                else -> {}
            }
        }

        private fun onBindLongImage(itemView: View, position: Int){
            val binding = ItemLongImageBinding.bind(itemView)
            val other = dataList[position].other
            val info = dataList[position].image

            val p = binding.image.layoutParams
            p.height = (usableWidth / (info.with / (info.bottom - info.top).toFloat())).toInt()
            binding.image.layoutParams = p

            val decoder = if (urlMap[info.path].isNullOrEmpty()){
                val file = ImageUtil.obtainCachedPictureFiles(info.path)
                if (file == null){
                    binding.image.setImageResource(R.color.color_eaeaea)
                    return
                }else{
                    urlMap[info.path] = file.path
                    val decoder = createBitmapRegionDecoder(file.path)
                    imageDecoder[file.path] = decoder
                    decoder
                }
            }else{
                imageDecoder[urlMap[info.path]?:""]
            }

            try {
                val proportion = (decoder?.width?:0) / info.with.toFloat()
                val mRect = Rect()
                mRect.top = (info.top * proportion).toInt()
                mRect.bottom = (info.bottom * proportion).toInt()
                mRect.left = 0
                mRect.right = decoder?.width?:0

                val b = decoder?.decodeRegion(mRect, bitmapOption)

                when(info.index){
                    0 -> {
                        binding.root.setPadding(0, 16.dp, 0, 0)
                        binding.image.setImageBitmapRound(b,2.dp,true)
                    }
                    2 -> {
                        binding.root.setPadding(0, 0, 0, 16.dp)
                        binding.image.setImageBitmapRound(b,2.dp,false)
                    }
                    else -> {
                        binding.root.setPadding(0, 0, 0, 0)
                        binding.image.setImageBitmap(b)
                    }
                }
            }catch (e :Exception){
                e.printStackTrace()
            }
        }

        private fun createBitmapRegionDecoder(filePath: String):BitmapRegionDecoder?{
            try {
                return BitmapRegionDecoder.newInstance(filePath,false)
            }catch (e:Exception){}
            return null
        }


        private fun onBindHeadViewHolder() = Unit

        private fun onBindContentViewHolder(itemView: View, position: Int){
            val binding = ItemArticleContentBinding.bind(itemView)
            binding.itemContentRoot.setPadding(16.dp,8.dp,16.dp,8.dp)
            val item = dataList[position].other
            if(item.type == ITEM_IMAGE){
                binding.text.visibility = View.GONE
                binding.image.visibility = View.VISIBLE
                if((item.image?.height?:0) > (item.image?.width?:0) * 2){
                    ImageUtil.updateImageFromNetwork(binding.image, item.image?.url?:"", item.image?.width?:0, item.image?.height?:0, ImageUtil.imageMaxSize)
                }else {
                    ImageUtil.updateImageFromNetwork(binding.image, item.image?.url, ImageRequest.CacheChoice.DEFAULT)
                }
                val params = binding.image.layoutParams as ViewGroup.LayoutParams
                params.width = contentImageWidth
                if((item.image?.width?:0) > 0 && (item.image?.height?:0) > 0){
                    params.height = (item.image?.height!!.toDouble() / item.image?.width!!.toDouble() * params.width).toInt()
                }
                binding.image.layoutParams = params
            }else if(item.type == ITEM_TEXT){ // text
                binding.text.visibility = View.VISIBLE
                binding.image.visibility = View.GONE
                binding.text.setTextColor(itemView.context.resources.getColor(R.color.color_666666))
                binding.text.letterSpacing = 0F
                binding.text.textSize = 13F
                binding.text.text = item.content
            }
        }

        private fun onBindFlowViewHolder(itemView: View, position: Int){
            val binding = ItemActivitiesFlowBinding.bind(itemView)
            val item = dataList[position].other.theme
            item?.let {
                binding.tvTitle.text = item.title
                binding.tvDesc.text = item.desc
            }
        }

        private fun onBindTailViewHolder(itemView: View){
            val binding = ItemActivitiesTailBinding.bind(itemView)
            if (mViewModel.info?.phone.isNullOrEmpty()){
                binding.clContactInformation.visibility = View.GONE
            }else{
                binding.clContactInformation.visibility = View.VISIBLE
            }
            binding.clContactInformation.click {
                showPhoneNumberDialog()
            }
        }

        override fun getItemCount(): Int {
            return dataList.size
        }

    }

    override fun onBackPressed() {
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()
        GlobalContextManager.mainHandler.removeCallbacks(finishRunnable)
    }


}